package com.vitaf.cash.app.ui.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.vitaf.cash.app.R
import com.vitaf.cash.app.utils.VitafImgLoader
import com.vitaf.cash.lib.adapter.VitafRecyclerViewAdapter
import com.vitaf.cash.lib.adapter.VitafViewHolderHelper
import com.vitaf.cash.lib.shapeview.layout.VitafConstraintLayout
import org.json.JSONObject

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/25 11:51
 * @Annotation：贷款详情 - 账户列表
 */
class VitafStatusDetailsWalletApt(recyclerView: RecyclerView?) : VitafRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.vitaf_fmt_status_details_wallet_item) {
    override fun setItemChildListener(helper: VitafViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.walletDelete) //点击Item
    }
    override fun fillData(helper: VitafViewHolderHelper, position: Int, model: JSONObject) {
        var showName = model.optString("name","")
        if (showName.isEmpty() || showName == "null"){
            showName = "test"
        }
        helper.setText(R.id.walletTypeTitle,showName)
        helper.setText(R.id.walletAccountMobile,"+" + model.optString("account"))
        val imgLogo = helper.getImageView(R.id.walletTypeLogo)
        VitafImgLoader.instance?.loadImageUrl(mContext,imgLogo,model.optString("logo"), R.mipmap.gombe_credit_image_holder)

        val itemLayout = helper.getView<VitafConstraintLayout>(R.id.itemLayout)
        if (showName.uppercase().startsWith("W")){
            itemLayout.getShapeDrawableBuilder()
                .setSolidColor(getColor(R.color.gombe_credit_FFF1FCFF))
                .setStrokeColor(getColor(R.color.gombe_credit_FFDCF7FF))
                .intoBackground()
        } else {
            itemLayout.getShapeDrawableBuilder()
                .setSolidColor(getColor(R.color.gombe_credit_FFFFF6F1))
                .setStrokeColor(getColor(R.color.gombe_credit_FFFFE9DC))
                .intoBackground()
        }

        if (model.optBoolean("isShowDelete",false)){
            helper.setVisibility(R.id.walletDelete, View.VISIBLE)
        } else {
            helper.setVisibility(R.id.walletDelete, View.INVISIBLE)
        }
    }
}